package com.tedu.ivos.user.controller;

import com.tedu.ivos.base.response.JsonResult;
import com.tedu.ivos.user.pojo.dto.UserLoginParam;
import com.tedu.ivos.user.pojo.dto.UserQuery;
import com.tedu.ivos.user.pojo.dto.UserSaveParam;
import com.tedu.ivos.user.pojo.vo.UserVO;
import com.tedu.ivos.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@Api(tags = "用户管理")
@RestController
@RequestMapping("/v1/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation(value = "用户登录功能")
    @PostMapping("/login")
    public JsonResult login(@RequestBody UserLoginParam userLoginParam){
        log.debug("用户登录userLoginParam:{}", userLoginParam);
        // 调用业务层的login方法
        UserVO userVO=userService.login(userLoginParam);
        // 将业务层返回的userVO 对象封装到JsonResult中，放回给前端
        return JsonResult.ok(userVO);
    };
    @ApiOperation(value = "员工信息保存功能/修改更新")
    @PostMapping("/save")
    public JsonResult saveUser(UserSaveParam userSaveParam){
        log.debug("员工信息保存userSaveParam:{}", userSaveParam);
        userService.saveUser(userSaveParam);
        // 判断是否新增成功
        return JsonResult.ok();
    }
    @ApiOperation(value = "查询员工数据")
    @GetMapping("/select")
    public JsonResult selectUser(UserQuery userQuery){
        log.debug("查询员工数据userQuery:{}", userQuery);
        List<UserVO> list=userService.selectUser(userQuery);
        return JsonResult.ok(list);
    }
    @ApiOperation(value = "重置密码功能")
    @PostMapping("/update/password/{userId}")
    public JsonResult resetPassword(@PathVariable Long userId){
        log.debug("重置密码userId:{}", userId);
        userService.resetPassword(userId);
        return JsonResult.ok();
    }
    @ApiOperation(value = "修改用户状态")
    @PostMapping("/update/status/{userId}/{status}")
    public JsonResult updateStatus(@PathVariable Long userId,@PathVariable String status){
        log.debug("修改用户状态userId:{},status:{}", userId, status);
        userService.updateStatus(userId, status);
        return JsonResult.ok();
    }
    @ApiOperation(value = "删除员工信息")
    @PostMapping("/delete/{userId}")
    public JsonResult deleteUser(@PathVariable Long userId){
        log.debug("删除员工信息userId:{}", userId);
        userService.deleteUser(userId);
        return JsonResult.ok();
    }

}
